package com.neuedu.api.date;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

/**
 * @author 金山
 * 项目：javase
 * site: https://blog.fulfill.com.cn
 * 描述
 * @data 2024/10/2412:12
 */
public class MyCalendar {

    public static void main(String[] args) {

        //获取所有时区
        String[] availableIDs = TimeZone.getAvailableIDs();
        for (String availableID : availableIDs) {
            System.out.println("availableID = " + availableID);
        }
        


        //对象的创建
        Calendar c1 = Calendar.getInstance();
        Calendar c2 = Calendar.getInstance(TimeZone.getTimeZone("GMT+8"));
        Calendar c3 = Calendar.getInstance(TimeZone.getTimeZone("US/Hawaii"));

        System.out.println("c1 = " + c1.getClass());
        System.out.println("c2 = " + c2.getClass());
        System.out.println("c3 = " + c3.getClass());


        //获取年月日、xxxxx 各种字段
        int year = c1.get(Calendar.YEAR);
        int month = c1.get(Calendar.MONTH) + 1 ;
        int date= c1.get(Calendar.DAY_OF_MONTH);
        int hours = c1.get(Calendar.HOUR_OF_DAY);
        int mins = c1.get(Calendar.MINUTE);
        int second = c1.get(Calendar.SECOND);
        int dayOfYear = c1.get(Calendar.DAY_OF_YEAR);


        //格式话的输出
        System.out.println(year+"-"+month+"-"+date+" "+hours+":"+mins+":"+second+" ,一年已经过了"+dayOfYear);



        //Calendar  --》  Date  -   SimpleDateFormat  ()  --- > 字符串

        Date time = c1.getTime();

        String pattern = "yyyy-MM-dd HH:mm:ss";
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);

        System.out.println("sdf.format(time) = " + sdf.format(time));



        Calendar d1 = Calendar.getInstance();
        Calendar d2 = Calendar.getInstance();
        System.out.println("d1.getTimeZone() = " + d1.getTimeZone());

        //设置字段
        d2.set(Calendar.MONTH,11);



        System.out.println("d1: " + sdf.format(d1.getTime()));
        System.out.println("d12: " + sdf.format(d2.getTime()));



        d2.add(Calendar.DAY_OF_MONTH,10);
        d2.add(Calendar.DAY_OF_MONTH,-2);

        System.out.println("d2.add(Calendar.DAY_OF_MONTH,10): " + sdf.format(d2.getTime()));

        System.out.println("d1.before(d2) = " + d1.before(d2));  //true d1 2024-10-24  d2: 2025-01-03
        System.out.println("d2.before(d1) = " + d2.before(d1));  //false
        System.out.println("d1.before(d1) = " + d1.before(d1));  //false

        System.out.println("d1.after(d2) = " + d1.after(d2));  //false
        System.out.println("d2.after(d1) = " + d2.after(d1));  //true
        System.out.println("d1.after(d1) = " + d1.after(d1));   //false

        System.out.println("d1.compareTo(d2) = " + d1.compareTo(d2));  // -1
        System.out.println("d2.compareTo(d1) = " + d2.compareTo(d1));  // 1
        System.out.println("d1.compareTo(d1) = " + d1.compareTo(d1));   // 0


        long timeInMillis = d1.getTimeInMillis();//


        // d1.
    }
}
